import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import 'rc-drawer-menu/assets/index.css';
import React from 'react';
import { connect } from 'dva';
import { withRouter } from 'dva/router';
import DrawerMenu from 'rc-drawer-menu';
import SiderMenu from "./SiderMenu";

var SiderMenuWrapper = /*#__PURE__*/function (_React$Component) {
  _inherits(SiderMenuWrapper, _React$Component);

  var _super = _createSuper(SiderMenuWrapper);

  function SiderMenuWrapper() {
    var _this;

    _classCallCheck(this, SiderMenuWrapper);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _this.handleMenuCollapse = function (collapsed) {
      _this.props.dispatch({
        type: 'global/changeLayoutCollapsed',
        payload: collapsed
      });
    };

    return _this;
  }

  _createClass(SiderMenuWrapper, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          _this$props$collapsed = _this$props.collapsed,
          collapsed = _this$props$collapsed === void 0 ? false : _this$props$collapsed,
          _this$props$isMobile = _this$props.isMobile,
          isMobile = _this$props$isMobile === void 0 ? false : _this$props$isMobile;
      return isMobile ? /*#__PURE__*/React.createElement(DrawerMenu, {
        parent: null,
        level: null,
        iconChild: null,
        open: !collapsed,
        onMaskClick: this.handleMenuCollapse,
        width: "256px"
      }, /*#__PURE__*/React.createElement(SiderMenu, Object.assign({}, this.props, {
        collapsed: isMobile ? false : collapsed
      }))) : /*#__PURE__*/React.createElement(SiderMenu, Object.assign({}, this.props, {
        collapsed: collapsed,
        onCollapse: this.handleMenuCollapse
      }));
    }
  }]);

  return SiderMenuWrapper;
}(React.Component);

export default withRouter(connect(function (_ref) {
  var _ref$global = _ref.global,
      global = _ref$global === void 0 ? {} : _ref$global;
  return {
    collapsed: global.collapsed,
    language: global.language // todo 当语言更新时, SiderMenu 也需要更新

  };
})(SiderMenuWrapper));